<template>
  <a-card title="文章">
    <vp-dynamic-table
      :call-server="callServer"
      rowKey="key"
      :columns="columns"
      :row-selection="{
        selectedRowKeys: state.selectedRowKeys,
        onChange: onSelectChange,
      }"
    ></vp-dynamic-table>
  </a-card>
</template>
<script lang="ts" setup>
import { reactive, ref, createVNode } from "vue";
import { getList } from "@/api/post";
const state = reactive<{
  selectedRowKeys: string[];
  loading: boolean;
}>({
  selectedRowKeys: [], // Check here to configure the default column
  loading: false,
});
const onSelectChange = (selectedRowKeys: string[]) => {
  console.log("selectedRowKeys changed: ", selectedRowKeys);
  state.selectedRowKeys = selectedRowKeys;
};
const dataSource = ref<any>([
  {
    id: "1",
    name: "胡彦斌",
    age: 32,
    address: "西湖区湖底公园1号",
  },
  {
    id: "2",
    name: "胡彦祖",
    age: 42,
    address: "西湖区湖底公园1号",
  },
]);
const columns = ref<any>([
  {
    title: "姓名",
    dataIndex: "name",
    key: "name",
    headerRender: (column) => {
      return createVNode("div", {}, column.key);
    },
    render: (item) => {
      return createVNode("div", {}, item.name);
    },
  },
  {
    title: "年龄",
    dataIndex: "age",
    key: "age",
  },
  {
    title: "住址",
    dataIndex: "address",
    key: "address",
  },
  {
    title: "操作",
    key: "action",
    actions: [
      {
        text: "123",
        props: {
          type: "primary",
        },
        func: (item) => {
          console.log(item);
        },
      },
      {
        text: "234",
        type: "popconfirm",
        content: "asdsa?",
        func: (item) => {
          console.log(item);
        },
      },
      {
        text: "234",
        type: "dropdown",
        content: "asdsa?",
        func: (item) => {
          console.log(item);
        },
      },
    ],
  },
]);
const callServer = () => {
  return new Promise<void>((resolve, reject) => {
    getList().then((data) => {
      let result: any = {
        current: 1,
        pages: 2,
        records: [
          {
            key: "1",
            name: "胡彦斌",
            age: 32,
            address: "西湖区湖底公园1号",
          },
          {
            key: "2",
            name: "胡彦祖",
            age: 42,
            address: "西湖区湖底公园1号",
          },
        ],
        size: 20,
        total: 30,
      };
      resolve(result);
    });
  });
};
</script>
